<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>个人中心</title>
		<link rel="stylesheet" type="text/css" href="layui/css/layui.css"/>
		<script src="layui/layui.js" type="text/javascript" charset="utf-8"></script>
		<script src="js/jquery-1.4.2.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<form class="layui-form" action="">
			<div class="layui-upload">
				<label class="layui-form-label">头像</label>
			  <div class="layui-upload-list" >
			    <img class="layui-upload-img" id="img1" style="width: 100px; height: 100px;">
				</div>
				<div class="layui-upload">
					<label class="layui-form-label"></label>
					<button type="button" class="layui-btn layui-btn-xs" id="img">上传图片</button>
					<button type="reset" class="layui-btn layui-btn-primary layui-btn-xs">重置</button>
					<p id="demoText"></p>
					<div id="find"></div>
				</div>

			  </div>
		</form>
		<form class="layui-form" id="infoSubmit">
			</div> 
		    <div class="layui-form-item">
		        <label class="layui-form-label">ID</label>
		        <div class="layui-input-inline">
		            <input type="text" readonly="readonly" name="userId" id="userId" required  lay-verify="required" class="layui-input layui-btn-disabled"/>
		        </div>
		    </div>
		    <div class="layui-form-item">
		        <label class="layui-form-label">姓名</label>
		        <div class="layui-input-inline">
		            <input type="text" readonly="readonly" id="realName" name="realName"  required  lay-verify="required" class="layui-input layui-btn-disabled" />
		        </div>
		    </div>
		
		<div class="layui-form-item">
		    <label class="layui-form-label">用户名</label>
		    <div class="layui-input-inline">
		        <input type="text" id="username" readonly="readonly" name="username"  required  lay-verify="required" class="layui-input layui-btn-disabled" />
		    </div>
		</div>

			<div class="layui-form-item">
				<label class="layui-form-label">账号类型</label>
				<div class="layui-input-inline">
					<input type="text" readonly="readonly" id="authority" name="authority"  required  lay-verify="required" class="layui-input layui-btn-disabled" />
				</div>
			</div>
		
		    <div class="layui-form-item">
		        <label class="layui-form-label">性别</label>
		        <div class="layui-input-inline">
		            <input type="text" id="sex" name="sex" required  lay-verify="required" class="layui-input " />
		        </div>
		    </div>

			<div class="layui-form-item">
			    <label class="layui-form-label">密码</label>
			    <div class="layui-input-inline">
			        <input type="password" id="password" name="password" required  lay-verify="required" class="layui-input " />
			    </div>
			</div>
			

		    <div class="layui-form-item">
		        <label class="layui-form-label">电话</label>
		        <div class="layui-input-inline">
		            <input type="text" id="tel" name="tel" required  lay-verify="required" class="layui-input " />
		        </div>
		    </div>
		    <div class="layui-form-item">
		        <label class="layui-form-label">邮箱</label>
		        <div class="layui-input-inline">
		            <input type="email" id="email" name="email" required  lay-verify="required" class="layui-input " />
		        </div>
		    </div>


			<div class="layui-form-item">
				<div class="layui-input-block">
					<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
					<button type="reset" class="layui-btn layui-btn-primary">清空</button>
				</div>
			</div>
		    
		
		</form>




		<script>
			var upload = layui.upload
			//Demo
			layui.use('form', function(){
				var form = layui.form;
				var laydate=layui.laydate;

				laydate.render({
					elem:'#birthday',
					type:'datetime'
				});
				//监听提交
				form.on('submit(formDemo)', function(data){
					layer.msg(JSON.stringify(data.field));
					return false;
				});

			});



			layui.use('jquery',function () {
				var $=layui.jquery;
				form.on('submit(formDemo)',function (data) {
					$.ajax({
						url:"http://localhost:8080/api/user/setUserInformation",
						method:"PUT",
						data:$('#infoSubmit').serialize(),
						success:function(res){
							if (res.code==200){
								layer.msg("修改成功",{time:1000})
							}else{
								layer.msg("修改失败",{time:1000})
							}
						},
						error:function(){
							layer.alert("发生异常！请重试")
						}
					})
					return false;
				});
			});


			var $ = layui.jquery
					,upload = layui.upload
					,element = layui.element
					,layer = layui.layer
					,form = layui.form;
			//监听提交

			form.on('submit(formDemo)', function(data){
				layer.msg(JSON.stringify(data.field));
				return false;
			});
			form.on('submit(formDemo2)', function(data){
				layer.msg(JSON.stringify(data.field));
				return false;
			});
			//常规使用 - 普通图片上传
			var uploadInst = upload.render({
				elem: '#img'
				,url: '/api/user/getUserImage' //改成您自己的上传接口
				,before: function(obj){
					//预读本地文件示例，不支持ie8
					obj.preview(function(index, file, result){
						$('#img1').attr('src', result); //图片链接
					});

				}
				,done: function(res){
					//如果上传失败
					if(res.code != 200){
						return layer.msg('上传失败');
					}
					//上传成功的一些操作
					//……
					return layer.msg("上传成功")
					// $('#demoText').html(''); //置空上传失败的状态
				}
				,error: function(){
					//演示失败状态，并实现重传
					var demoText = $('#demoText');
					demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
					demoText.find('.demo-reload').on('click', function(){
						uploadInst.upload();
					});
				}
			});

		</script>

	<script>
		$(function(){
		    $.ajax({
				url:"/api/user/selectUserByUserName",
				method:"GET",
				success:function (res) {
					$("#userId").val(res.data.userId)
					$("#realName").val(res.data.realName)
					$("#sex").val(res.data.sex)
					$("#username").val(res.data.username)
					$("#password").val(res.data.password)
					$("#authority").val(res.data.authority)
					$("#tel").val(res.data.tel)
					$("#email").val(res.data.email)
                }
			})
		});

	</script>
	</body>
</html>

